#!/usr/bin/env python

# Script to update all of the verification plots

import os, sys
from optparse import OptionParser


parser = OptionParser()
parser.add_option('--u22', dest='usl22z_flag', action='store_true', default=False, help= "Option to write 22Z USL or not")

(opts,args) = parser.parse_args()
usl22z_flag = opts.usl22z_flag

# Load in the info
from INFILE import siteid,wfoid,maindir
sys.path.append('%s/data_parsers' % maindir)
from surface_parse_bufkit import get_todays_verification

pycmd = '/home/disk/pvort/lmadaus/nobackup/pylibs/epd/bin/python'

def main():
    curdir = os.getcwd()
    
    # Get the latest NWS and USL
    os.chdir('%s/data_parsers' % maindir)
    os.system('python scrub_nws.py')
    os.system('python scrub_USL.py')
    os.chdir(curdir)

    # Update the GFSE
    os.chdir('%s/gfs_ensemble_mos' % maindir)
    os.system('./plot_current_gfse.py -s %s -e' % siteid.upper())
    os.chdir(curdir)

    # Get in the right directory
    os.chdir('%s/verify' % maindir)
    # Run the verification for each model
    os.system('./make_verification.py -m GFS -v all -e')
    os.system('./make_verification.py -m NAM -v all -e')
    os.system('./make_verification.py -m NWS -v all -e')
    os.system('./make_verification.py -m USL12Z -v all -e')
    os.system('./make_verification.py -m USL22Z -v all -e')
    os.chdir(curdir)

    # Update the HPC percentiles
    os.system('%s %s/hpc_pqpf/hpc_precip_pctiles.py' % (pycmd,maindir))
    #os.system('%s/hrmos_qpf/gfs_hrmos_qpf.py' % maindir)

    # Plot the precipitation errors
    os.chdir(maindir)
    os.system('%s/plot_precip_errors.py' % maindir)

if __name__ == '__main__':
    main()
